package cloud.tianai.ram.policy.common.handler;

import cloud.tianai.ram.policy.common.exception.ConditionHandlerNotFoundException;
import cloud.tianai.ram.policy.common.model.dto.Match;
import cloud.tianai.ram.policy.common.model.dto.Action;
import cloud.tianai.ram.policy.common.model.dto.Condition;
import cloud.tianai.ram.policy.common.model.dto.TypeDefinition;

import java.util.Collection;
import java.util.List;

/**
 * @Author: 天爱有情
 * @date 2022/3/7 14:02
 * @Description 条件处理程序管理器
 */
public interface ConditionHandlerManager extends StandardMatchHandler {

    /**
     * 添加 ConditionHandler
     *
     * @param condition ConditionHandler
     */
    void addConditionHandler(ConditionHandler condition);

    /**
     * 通过类型获取  ConditionHandler
     * @param operationType 类型
     * @return ConditionHandler
     */
    ConditionHandler getConditionHandler(String operationType);

    /**
     * 通过  Condition 获取 ConditionHandler
     * @param condition condition
     * @return ConditionHandler
     */
    ConditionHandler getConditionHandler(Condition condition);

    /**
     * 列出支持的 条件 type定义
     * @return TypeDefinition
     */
    List<TypeDefinition> listSupportedTypes();
    /**
     * 通过类型删除 ConditionHandler
     *
     * @param operationType 类型
     * @return ConditionHandler
     */
    boolean removeConditionHandler(String operationType);

    /**
     * 获取所有的 ConditionHandler
     *
     * @return Collection<ConditionHandler>
     */
    Collection<ConditionHandler> getConditionHandlers();

    /**
     * 匹配条件是否成立
     *
     * @param conditionList conditionList
     * @param action action
     * @return Match
     * @throws ConditionHandlerNotFoundException
     */
    Match match(List<Condition> conditionList, Action action) throws ConditionHandlerNotFoundException;

    /**
     * 匹配条件是否成立
     *
     * @param condition condition
     * @param action action
     * @return Match
     * @throws ConditionHandlerNotFoundException ex
     */
    Match match(Condition condition, Action action) throws ConditionHandlerNotFoundException;

}
